import pygame
from pygame.locals import *

class Widget:
   def __init__(self):
      """ 
         Accepts no args. This is the basic gui object where all others come from. define the parent
         and children lists, set alive to yes, and define the onclick event stack. Finally get the 
         pygame surface 
      """
      self.parent = None
      self.children = []
      self.alive = True
      self.onClick = []
      self.screen = pygame.display.get_surface()
      self.can_drag = False
      self.rect = None
   
   def add(self, widget):
      """ 
         The add method allows you to add any widget to any other widget as a child. It takes the object 
         passes, adds a refrence to the parent attribute and appends the object to the children.
      """
      widget.parent = self
      self.children.append(widget)

   def get_x(self):
      """ Returns the self.x taking the parent window into account """
      if self.parent: return self.rect.x + self.parent.rect.x
      else: return self.rect.x
         
   def get_y(self):
      """ Returns the self.x taking the parent window into account """
      if self.parent: return self.rect.y + self.parent.rect.y
      else: return self.rect.y

   def move(self, loc):
      """
         Moves the widget by applying a tuple 'loc'.
      """
      self.rect.left += loc[0]
      self.rect.top += loc[1]
      
   def move_to(self, loc):
      """
         Moves the widget to the location specified by 'loc'
      """
      self.rect.left += loc[0]
      self.rect.top += loc[1]
      
   def kill(self):
      """
         simply sets the alive attribute to false.
      """
      self.alive = False